package vn.evolus.pencil.utils;

import java.text.SimpleDateFormat;

import vn.evolus.pencil.model.Collection;
import vn.evolus.pencil.viewmodel.CollectionViewModel;

public class MappingUtil {
	public static CollectionViewModel mappingCollection(Collection collection, String contextUrl){
		CollectionViewModel collectionViewModel = new CollectionViewModel();
		collectionViewModel.setId(collection.getId());
		collectionViewModel.setDescription(collection.getDescription());
		collectionViewModel.setCollectionId(collection.getCollectionId());
		
		String dateFormatPattern = "MM/dd/yyyy HH:mm:ss aaa";
		SimpleDateFormat simpleDateFormat= new SimpleDateFormat(dateFormatPattern);
		collectionViewModel.setLastUpdate(simpleDateFormat.format(collection.getLastUpdate()));
		
		collectionViewModel.setName(collection.getName());
		collectionViewModel.setAuthor(collection.getAuthor());
		
		String urlPackage = String.format("%s/%s?id=%s", contextUrl, "getPackage", collection.getId());
		collectionViewModel.setPackageUrl(urlPackage);
		String urlIcon = String.format("%s/%s?id=%s", contextUrl, "getIconImage", collection.getId());
		collectionViewModel.setIcon(urlIcon);
		
		return collectionViewModel;
	}
}
